package 作业1;

import java.util.Scanner;

public class LoanCalculator {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    // 输入年利率
    System.out.print("请输入年利率（例如，5.0表示5%）: ");
    double annualInterestRate = input.nextDouble();

    // 输入总金额
    System.out.print("请输入总金额: ");
    double loanAmount = input.nextDouble();

    // 输入年数
    System.out.print("请输入年数: ");
    int numberOfYears = input.nextInt();

    // 计算月利率
    double monthlyInterestRate = annualInterestRate / 12 / 100;

    // 计算每月支付额
    double monthlyPayment =
      (loanAmount * monthlyInterestRate) /
      (1 - Math.pow(1 + monthlyInterestRate, -numberOfYears * 12));

    // 计算总偿还金额
    double totalPayment = monthlyPayment * numberOfYears * 12;

    // 显示结果
    System.out.println("每月支付额: " + monthlyPayment);
    System.out.println("总偿还金额: " + totalPayment);


  }
}
